package com.originskyseed.platform.course.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.course.mapper.CourseRelateIsReadMapper;
import com.originskyseed.platform.course.model.CourseRelateIsRead;
import com.originskyseed.platform.course.service.ICourseRelateIsReadService;

/**
 * 课程关联人员是否查看表Service接口实现类（OSI_COURSE_RELATE_IS_READ）
 *
 * @author wlj
 */
@DubboService
@Component("courseRelateIsReadService")
public class CourseRelateIsReadServiceImpl implements ICourseRelateIsReadService {

	@Resource
	private CourseRelateIsReadMapper courseRelateIsReadMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.courseRelateIsReadMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.courseRelateIsReadMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(CourseRelateIsRead record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.courseRelateIsReadMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(CourseRelateIsRead record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.courseRelateIsReadMapper.insertSelective(record);
	}

	/**
	 * 批量新增
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertBatch(List<CourseRelateIsRead> list) throws Exception {
		return this.courseRelateIsReadMapper.insertBatch(list);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(CourseRelateIsRead record) throws Exception {
		record.setUpdateTime(new Date());
		return this.courseRelateIsReadMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(CourseRelateIsRead record) throws Exception {
		record.setUpdateTime(new Date());
		return this.courseRelateIsReadMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 修改已读
	 * @param courseId
	 * @param objId
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateIsRead(String courseId, String objId) throws Exception {
		return this.courseRelateIsReadMapper.updateIsRead(courseId,objId);
	}

	/**
	 * 查询是否已读
	 * @param courseId
	 * @param objId
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer selectIsRead(String courseId, String objId) throws Exception {
		return this.courseRelateIsReadMapper.selectIsRead(courseId,objId);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public CourseRelateIsRead selectByPrimaryKey(String id) throws Exception {
		return this.courseRelateIsReadMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<CourseRelateIsRead> selectList(CourseRelateIsRead record) throws Exception {
		return this.courseRelateIsReadMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<CourseRelateIsRead> selectListByPage(Map<String, Object> params, BasePage<CourseRelateIsRead> page) throws Exception {
		params.put("page", page);
		List<CourseRelateIsRead> list = this.courseRelateIsReadMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 统计未读
	 * @param objId
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer countIsReadNum(String objId) throws Exception {
		return this.courseRelateIsReadMapper.countIsReadNum(objId);
	}

}
